home *** CD-ROM | disk | FTP | other *** search
/ PC World Interactive 4 / PC World Interactive 4.iso / online / appbar.EXE / cppsrc / Newapp.cpp < prev    next >
C/C++ Source or Header  |  1996-08-31  |  4KB  |  140 lines

  1. // *********************************************************
  2. // AppBar -- Advanced Menu bar for Windows 95/NT
  3. // All code Copyright (C) 1995, 1996 by Mike Perham
  4. // mperham@cs.cornell.edu
  5. // 
  6. // This code MAY NOT be used for any other program without
  7. // my permission and is forbidden in any shareware/commercial
  8. // program.  This code is provided for educational use only
  9. // and there are no guarantees or promises implied.  Blah blah
  10. // *********************************************************
  11.  
  12. // NewApp.cpp : implementation file
  13. //
  14.  
  15. #include "appbar.h"
  16. #include "globals.h"
  17.  
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // NewApp dialog
  26.  
  27.  
  28. NewApp::NewApp(CWnd* pParent /*=NULL*/, hack *ph)
  29.     : CDialog(NewApp::IDD, pParent)
  30. {
  31.     //{{AFX_DATA_INIT(NewApp)
  32.     //}}AFX_DATA_INIT
  33.     phack = ph;
  34.     parent = pParent;
  35.     isnew = NULL;
  36. }
  37.  
  38. void inline NewApp::ab_message(char *msg)
  39. {
  40.     MessageBox(msg, "AppBar", MB_OK | MB_ICONINFORMATION);
  41. }
  42.  
  43. BEGIN_MESSAGE_MAP(NewApp, CDialog)
  44.     //{{AFX_MSG_MAP(NewApp)
  45.     ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
  46.     //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48.  
  49. /////////////////////////////////////////////////////////////////////////////
  50. // NewApp message handlers
  51.  
  52. void NewApp::OnOK() 
  53. {
  54.     char buf1[80], buf2[30];
  55.  
  56.     GetDlgItem(IDC_EXENAME)->SendMessage(WM_GETTEXT, sizeof(buf1), (LPARAM)buf1);
  57.     GetDlgItem(IDC_APPNAME)->SendMessage(WM_GETTEXT, sizeof(buf2), (LPARAM)buf2);
  58.     if ((!strcmp(buf1, "")) || (!strcmp(buf2, ""))) {
  59.         ab_message(ERROR_NAME_FILENAME);
  60.         return;
  61.     }
  62.     GetDlgItem(IDC_EXENAME)->SendMessage(WM_GETTEXT, sizeof(pnewapp->appexe), (LPARAM)pnewapp->appexe);
  63.     GetDlgItem(IDC_APPNAME)->SendMessage(WM_GETTEXT, sizeof(pnewapp->appname), (LPARAM)pnewapp->appname);
  64.     GetDlgItem(IDC_PARAMETERS)->SendMessage(WM_GETTEXT, sizeof(pnewapp->params), (LPARAM)pnewapp->params);
  65.     GetDlgItem(IDC_WORKINGDIR)->SendMessage(WM_GETTEXT, sizeof(pnewapp->workingdir), (LPARAM)pnewapp->workingdir);
  66.     if (!strcmp(pnewapp->workingdir, "")) {
  67.         char drive[40], path[80];
  68.         _splitpath(pnewapp->appexe, drive, path, NULL, NULL);
  69.         sprintf(pnewapp->workingdir, "%s%s", drive, path);
  70.         int len = strlen(pnewapp->workingdir);
  71.         if (len>3)
  72.             // remove trailing backslash on directory
  73.             *(pnewapp->workingdir + len - 1) = '\0';
  74.     }
  75.     if (IsDlgButtonChecked(IDC_NORMAL))
  76.         pnewapp->show = SW_RESTORE;
  77.       else if (IsDlgButtonChecked(IDC_MAX))
  78.         pnewapp->show = SW_MAXIMIZE;
  79.       else if (IsDlgButtonChecked(IDC_MIN))
  80.         pnewapp->show = SW_MINIMIZE;
  81.     if (isnew) {
  82.         if (phack->app) {
  83.             phack->app->nextapp = pnewapp;
  84.             pnewapp->prevapp = phack->app;
  85.           } else {            // first app in menu
  86.               phack->menu->nextapp = pnewapp;
  87.             pnewapp->prevapp = NULL;
  88.         }
  89.         menu->numapps++;
  90.         parent->SendDlgItemMessage(IDC_APPLIST, LB_INSERTSTRING, (WPARAM) -1, (LPARAM)pnewapp->appname);
  91.       } else {
  92.         parent->SendDlgItemMessage(IDC_APPLIST, LB_DELETESTRING, index, 0);
  93.            parent->SendDlgItemMessage(IDC_APPLIST, LB_INSERTSTRING, index, (LPARAM)pnewapp->appname);
  94.     }
  95.     EndDialog(TRUE);
  96. }
  97.  
  98. void NewApp::OnCancel() 
  99. {
  100.     if (isnew)
  101.            delete pnewapp;
  102.     CDialog::OnCancel();
  103. }
  104.  
  105. BOOL NewApp::OnInitDialog()
  106. {
  107.     CDialog::OnInitDialog();
  108.  
  109.     isnew = phack->isnew;
  110.     if (isnew) {
  111.         menu = phack->menu;
  112.         pnewapp = new app_struct;
  113.       } else 
  114.         pnewapp = phack->app;
  115.     switch (pnewapp->show) {
  116.         case SW_MAXIMIZE:
  117.             check_button = IDC_MAX;
  118.             break;
  119.         case SW_MINIMIZE:
  120.             check_button = IDC_MIN;
  121.             break;
  122.         default:
  123.             check_button = IDC_NORMAL;
  124.             break;
  125.     }
  126.     CheckRadioButton(IDC_NORMAL, IDC_MIN, check_button);
  127.     index = parent->SendDlgItemMessage(IDC_APPLIST, LB_GETCURSEL, 0, 0);
  128.     GetDlgItem(IDC_EXENAME)->SendMessage(WM_SETTEXT, 0, (LPARAM)pnewapp->appexe);
  129.     GetDlgItem(IDC_APPNAME)->SendMessage(WM_SETTEXT, 0, (LPARAM)pnewapp->appname);
  130.     GetDlgItem(IDC_WORKINGDIR)->SendMessage(WM_SETTEXT, 0, (LPARAM)pnewapp->workingdir);
  131.     GetDlgItem(IDC_PARAMETERS)->SendMessage(WM_SETTEXT, 0, (LPARAM)pnewapp->params);
  132.     GetDlgItem(IDC_APPNAME)->SetFocus();
  133.     return FALSE;
  134. }
  135.  
  136. void NewApp::OnBrowse() 
  137. {
  138.     DoBrowse(0, this);
  139. }
  140.